package org.wu.framework.authorization.platform.application.impl;

import jakarta.annotation.Resource;
import org.wu.framework.authorization.platform.application.SysZoneApplicationApplication;
import org.wu.framework.authorization.platform.application.assembler.SysZoneApplicationDTOAssembler;
import org.wu.framework.authorization.platform.application.command.sys.zone.application.*;
import org.wu.framework.authorization.platform.application.dto.SysZoneApplicationDTO;
import org.wu.framework.authorization.platform.domain.model.sys.zone.application.SysZoneApplication;
import org.wu.framework.authorization.platform.domain.model.sys.zone.application.SysZoneApplicationRepository;
import org.wu.framework.lazy.orm.database.lambda.domain.LazyPage;
import org.wu.framework.lazy.orm.web.plus.stereotype.LazyApplication;
import org.wu.framework.web.response.Result;

import java.util.List;
import java.util.stream.Collectors;
/**
 * describe 应用信息 
 *
 * @author Jia wei Wu
 * @date 2024/04/02 06:21 晚上
 * @see org.wu.framework.lazy.orm.core.persistence.reverse.lazy.ddd.DefaultDDDLazyApplicationImpl 
 **/
@LazyApplication
public class SysZoneApplicationApplicationImpl implements SysZoneApplicationApplication {

    @Resource
    SysZoneApplicationRepository sysZoneApplicationRepository;
    /**
     * describe 新增应用信息
     *
     * @param sysZoneApplicationStoryCommand 新增应用信息
     * @return {@link Result< SysZoneApplication >} 应用信息新增后领域对象
     
     * @author Jia wei Wu
     * @date 2024/04/02 06:21 晚上
     **/

    @Override
    public Result<SysZoneApplication> story(SysZoneApplicationStoryCommand sysZoneApplicationStoryCommand) {
        SysZoneApplication sysZoneApplication = SysZoneApplicationDTOAssembler.INSTANCE.toLazyZoneApplication(sysZoneApplicationStoryCommand);
        return sysZoneApplicationRepository.story(sysZoneApplication);
    }
    /**
     * describe 批量新增应用信息
     *
     * @param sysZoneApplicationStoryCommandList 批量新增应用信息
     * @return {@link Result<List< SysZoneApplication >>} 应用信息新增后领域对象集合
     
     * @author Jia wei Wu
     * @date 2024/04/02 06:21 晚上
     **/

    @Override
    public Result<List<SysZoneApplication>> batchStory(List<SysZoneApplicationStoryCommand> sysZoneApplicationStoryCommandList) {
        List<SysZoneApplication> sysZoneApplicationList = sysZoneApplicationStoryCommandList.stream().map( SysZoneApplicationDTOAssembler.INSTANCE::toLazyZoneApplication).collect(Collectors.toList());
        return sysZoneApplicationRepository.batchStory(sysZoneApplicationList);
    }
    /**
     * describe 更新应用信息
     *
     * @param sysZoneApplicationUpdateCommand 更新应用信息
     * @return {@link Result< SysZoneApplication >} 应用信息领域对象
     
     * @author Jia wei Wu
     * @date 2024/04/02 06:21 晚上
     **/

    @Override
    public Result<SysZoneApplication> updateOne(SysZoneApplicationUpdateCommand sysZoneApplicationUpdateCommand) {
        SysZoneApplication sysZoneApplication = SysZoneApplicationDTOAssembler.INSTANCE.toLazyZoneApplication(sysZoneApplicationUpdateCommand);
        return sysZoneApplicationRepository.story(sysZoneApplication);
    }

    /**
     * describe 查询单个应用信息
     *
     * @param sysZoneApplicationQueryOneCommand 查询单个应用信息
     * @return {@link Result< SysZoneApplicationDTO >} 应用信息DTO对象
     
     * @author Jia wei Wu
     * @date 2024/04/02 06:21 晚上
     **/

    @Override
    public Result<SysZoneApplicationDTO> findOne(SysZoneApplicationQueryOneCommand sysZoneApplicationQueryOneCommand) {
        SysZoneApplication sysZoneApplication = SysZoneApplicationDTOAssembler.INSTANCE.toLazyZoneApplication(sysZoneApplicationQueryOneCommand);
        return sysZoneApplicationRepository.findOne(sysZoneApplication).convert(SysZoneApplicationDTOAssembler.INSTANCE::fromLazyZoneApplication);
    }

    /**
     * describe 查询多个应用信息
     *
     * @param sysZoneApplicationQueryListCommand 查询多个应用信息
     * @return {@link Result<List< SysZoneApplicationDTO >>} 应用信息DTO对象
     
     * @author Jia wei Wu
     * @date 2024/04/02 06:21 晚上
     **/

    @Override
    public Result<List<SysZoneApplicationDTO>> findList(SysZoneApplicationQueryListCommand sysZoneApplicationQueryListCommand) {
        SysZoneApplication sysZoneApplication = SysZoneApplicationDTOAssembler.INSTANCE.toLazyZoneApplication(sysZoneApplicationQueryListCommand);
        return sysZoneApplicationRepository.findList(sysZoneApplication)        .convert(lazyZoneApplications -> lazyZoneApplications.stream().map(SysZoneApplicationDTOAssembler.INSTANCE::fromLazyZoneApplication).collect(Collectors.toList())) ;
    }

    /**
     * describe 分页查询多个应用信息
     *
     * @param sysZoneApplicationQueryListCommand 分页查询多个应用信息
     * @return {@link Result<LazyPage< SysZoneApplicationDTO >>} 分页应用信息DTO对象
     
     * @author Jia wei Wu
     * @date 2024/04/02 06:21 晚上
     **/

    @Override
    public Result<LazyPage<SysZoneApplicationDTO>> findPage(int size, int current, SysZoneApplicationQueryListCommand sysZoneApplicationQueryListCommand) {
        SysZoneApplication sysZoneApplication = SysZoneApplicationDTOAssembler.INSTANCE.toLazyZoneApplication(sysZoneApplicationQueryListCommand);
        return sysZoneApplicationRepository.findPage(size,current, sysZoneApplication)        .convert(page -> page.convert(SysZoneApplicationDTOAssembler.INSTANCE::fromLazyZoneApplication))            ;
    }

    /**
     * describe 删除应用信息
     *
     * @param sysZoneApplicationRemoveCommand 删除应用信息
     * @return {@link Result< SysZoneApplication >} 应用信息
     
     * @author Jia wei Wu
     * @date 2024/04/02 06:21 晚上
     **/

    @Override
    public Result<SysZoneApplication> remove(SysZoneApplicationRemoveCommand sysZoneApplicationRemoveCommand) {
     SysZoneApplication sysZoneApplication = SysZoneApplicationDTOAssembler.INSTANCE.toLazyZoneApplication(sysZoneApplicationRemoveCommand);
     return sysZoneApplicationRepository.remove(sysZoneApplication);
    }

}